<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>ajax文件上传</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="stylesheet" type="text/css" href="validate/ajaxfileupload.css" />
    <script type="text/javascript" src="third-party/jquery.min.js"></script>
    <script type="text/javascript" src="js/ajaxfileupload.js" ></script>
    <script type="text/javascript">
    $(function(){
       //上传图片
       $("#btnUpload").click(function() {
               alert(ajaxFileUpload());
       });
    });
    function ajaxFileUpload() {
    	$.ajaxFileUpload
    	(
    	    {
    	        url: 'main/insert', //用于文件上传的服务器端请求地址
    	        secureuri: false,           //一般设置为false
    	        fileElementId: 'file', //文件上传控件的id属性  <input type="file" id="file" name="file" /> 注意，这里一定要有name值   
    	                                                //$("form").serialize(),表单序列化。指把所有元素的ID，NAME 等全部发过去
    	        dataType: 'json',//返回值类型 一般设置为json
    	        complete: function () {//只要完成即执行，最后执行
    	        },
    	        success: function (data, status)  //服务器成功响应处理函数
    	        {         
    	        	alert(data);
    	        },
    	        error: function (data, status, e)//服务器响应失败处理函数
    	        {
    	            alert(e);
    	        }
    	    }
    	)
        //return false;
    }
    </script>
  </head>
  
  <body>
    <div id="wait_loading" style="padding: 50px 0 0 0;display:none;">
        <div style="width: 103px;margin: 0 auto;"><img src="images/addImage.jpg"/></div>
        <br></br>
        <div style="width: 103px;margin: 0 auto;"><span>请稍等...</span></div>
        <br></br>
    </div>
    <input type="file" id="file" name="file"><br/>
    <input type="hidden" id="flag" name="flag" value="ajax文件上传"/>
    <input type="button" id="btnUpload" value="上传图片" />
  </body>
</html>